package com.uu.look.web;

import com.uu.look.common.core.Code;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import org.uu.skull.result.ResultCreator;

/**
 * User : LiuKe
 * Date : 2016/12/30
 * Time : 16:37
 */
@ControllerAdvice
public class ExceptionHandlerAdvice {
    private final Logger log = LoggerFactory.getLogger(getClass());
    @ExceptionHandler(Exception.class)
    public ResponseEntity<Object> exception(Exception exception , WebRequest request) {

        try {
            throw exception;
        } catch (Exception e) {
            log.error(e.getMessage());
            return new ResponseEntity<Object>(ResultCreator.create(Code.SYSTEM_ERROR), HttpStatus.OK);
        }
    }
}
